package cn.com.code.design;

import cn.com.code.design.impl.CardCommodityService;
import cn.com.code.design.impl.CouponCommodityService;
import cn.com.code.design.impl.GoodsCommodityService;

/**
 * @author zhengpei
 * @date 2021/9/12
 */
public class StoreFactory {

  /**
   * 奖品类型方式实例化
   *
   * @param type 奖品类型
   * @return 实例化对象
   */
  public ICommondity getCommodityService(Integer type) {
    if (null == type) {
      return null;
    }
    if (1 == type) {
      return new CardCommodityService();
    }
    if (2 == type) {
      return new CouponCommodityService();
    }
    if (3 == type) {
      return new GoodsCommodityService();
    }
    throw new RuntimeException("不存在的奖品服务类型");
  }

  /**
   * 奖品类信息方式实例化
   * @param clazz 奖品类
   * @return      实例化对象
   */
  public ICommondity getCommodityService(Class<? extends ICommondity> clazz) throws IllegalAccessException, InstantiationException {
    if (null == clazz) {
      return null;
    }
    return clazz.newInstance();
  }

}
